package com.yunxin.core.infra.persistence.repository.popup;

import com.yunxin.core.domain.model.popup.PopupProductConfig;
import com.yunxin.core.domain.model.popup.PopupProductConfigRepository;
import com.yunxin.core.infra.persistence.converter.PopupConverter;
import com.yunxin.core.infra.persistence.entity.popup.PopupProductConfigDO;
import com.yunxin.core.infra.persistence.mapper.popup.PopupProductConfigExtendMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

/**
 * @author zero°
 * @since 2023-12-11
 */
@Repository
@RequiredArgsConstructor
public class PopupProductConfigRepositoryImpl implements PopupProductConfigRepository {

    private final PopupConverter popupConverter;

    private final PopupProductConfigExtendMapper popupProductConfigExtendMapper;

    @Override
    public boolean savePopupProductConfig(PopupProductConfig popupProductConfig) {
        PopupProductConfigDO popupProductConfigDO = popupConverter.formPopupProductConfig(popupProductConfig);
        int result = popupProductConfigExtendMapper.insertSelective(popupProductConfigDO);
        return result > 0;
    }

    @Override
    public String getLastPopupProductData(Long id, Integer releaseStatus) {
        return popupProductConfigExtendMapper.getLastPopupProductData(id, releaseStatus);
    }

}
